package com.example.admin.controller;

import com.example.admin.pojo.AddUser;
import com.example.admin.pojo.LoginUser;
import com.example.admin.service.AdUserService;
import com.example.admin.service.UserService;
import com.usian.model.admin.pojos.AdUser;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(tags = "用户接口说明")
@RequestMapping("/ad_user/v1")
public class AdUserController {
    @Autowired
    AdUserService adUserService;
    @Autowired
    UserService userService;
    
    
    @ApiOperation(notes = "注册",value = "注册")
    @PostMapping("/add_user")
    public ResponseResult addUser(@RequestBody AddUser addUser){
        return adUserService.addUser(addUser);
    }

    @ApiOperation(notes = "登录",value = "登录")
    @PostMapping("/login")
    public ResponseResult login(@RequestBody LoginUser loginUser){
        return adUserService.login(loginUser);
    }
    
    @GetMapping("/user_by_id")
    public ResponseResult   getUserById(Integer userId){
        AdUser adUser = userService.getUserById(userId);
        if (adUser==null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        return PageResponseResult.okResult(adUser);
        
    }
}
